/*************************************************************************
 *
 *   file		: Disenchant.cs
 *   copyright		: (C) The WCell Team
 *   email		: info@wcell.org
 *   last changed	: $LastChangedDate: 2009-03-28 12:40:05 +0000 (Sat, 28 Mar 2009) $
 *   last author	: $LastChangedBy: dominikseifert $
 *   revision		: $Rev: 828 $
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *************************************************************************/

using WCell.Constants;
using WCell.Constants.Looting;
using WCell.Constants.Skills;
using WCell.Constants.Spells;
using WCell.RealmServer.Looting;

namespace WCell.RealmServer.Spells.Effects
{
	/// <summary>
	/// Disenchant Visual (Id: 61335)
	/// </summary>
	public class DisenchantEffectHandler : SpellEffectHandler
	{
		public DisenchantEffectHandler(SpellCast cast, SpellEffect effect)
			: base(cast, effect)
		{
		}

		public override void Initialize(ref SpellFailedReason failReason)
		{
			var templ = m_cast.UsedItem.Template;
			if (templ.RequiredDisenchantingLevel == -1)
			{
				failReason = SpellFailedReason.CantBeDisenchanted;
			}
			else if (templ.RequiredDisenchantingLevel > m_cast.CasterChar.Skills.GetValue(SkillId.Enchanting))
			{
				failReason = SpellFailedReason.CantBeDisenchantedSkill;
			}
		}

		public override void Apply()
		{
			var caster = m_cast.CasterChar;
			caster.Emote(EmoteType.SimpleTalk);
			LootMgr.CreateAndSendObjectLoot(m_cast.UsedItem, caster, LootEntryType.Disenchanting, false);
			//m_cast.CasterChar.Inventory.AddAllUnchecked(loot, slots);
		}

		public override bool HasOwnTargets
		{
			get
			{
				return false;
			}
		}

		public override ObjectTypes CasterType
		{
			get
			{
				return ObjectTypes.Player;
			}
		}
	}
}
